package br.ufpi.componets.json.exclusion;


import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.Set;

import com.google.gson.ExclusionStrategy;
import com.google.gson.FieldAttributes;

public class CustomExclusionStrategy implements ExclusionStrategy {

    @SuppressWarnings("rawtypes")
	private final Set toExcludeClasses;
    private final Set<String> fieldsToExclude;

    @SuppressWarnings({ "unchecked", "rawtypes" })
	public CustomExclusionStrategy(Set<String> fieldsToExclude, Class<?>... classes) {
        this.fieldsToExclude = fieldsToExclude;
        this.toExcludeClasses = new LinkedHashSet(Arrays.asList(classes));
    }

    @Override
    public boolean shouldSkipField(FieldAttributes f) {
        return f.getAnnotation(DontSerialize.class) != null || fieldsToExclude.contains(f.getName());
    }

    @Override
    public boolean shouldSkipClass(Class<?> clazz) {
        return toExcludeClasses.contains(clazz);
    }
}